/***
 *
 *
 *                                                    __----~~~~~~~~~~~------___
 *                                   .  .   ~~//====......          __--~ ~~
 *                   -.            \_|//     |||\\  ~~~~~~::::... /~
 *                ___-==_       _-~o~  \/    |||  \\            _/~~-
 *        __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *    _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *  .~       .~       |   \\ -_    /  /-   /   ||      \   /
 * /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 * |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *          '         ~-|      /|    |-~\~~       __--~~
 *                      |-~~-_/ |    |   ~\_   _-~            /\
 *                           /  \     \__   \/~                \__
 *                       _--~ _/ | .-~~____--~-/                  ~~==.
 *                      ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                 -_     ~\      ~~---l__i__i__i--~~_/
 *                                 _-~-__   ~)  \--______________--~~
 *                               //.-~~~-~_--~- |-------~~~~~~~~
 *                                      //.-~~~--\
 *                               神兽保佑
 *                              代码无BUG!
 */
package com.qfedu.tantu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qfedu.tantu.dao.AdvertisementDao;
import com.qfedu.tantu.dao.EvalutionDao;
import com.qfedu.tantu.dto.DetailDto;
import com.qfedu.tantu.entity.Advertisement;
import com.qfedu.tantu.service.intf.DetailService;
import com.qfedu.tantu.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
@Service
public class DetailServiceImpl implements DetailService {
    @Resource
    private AdvertisementDao advertisementDao;
    @Resource
    private EvalutionDao evalutionDao;
    @Override
    public R selectDetail(int id) {
        if (id>0){
            QueryWrapper<Advertisement> advertisementQueryWrapper = new QueryWrapper<>();
            advertisementQueryWrapper.eq("id",id);
            //获取当前广告信息
            Advertisement advertisement = advertisementDao.selectOne(advertisementQueryWrapper);
            //获取用户信息及评论内容
            List<DetailDto> detailDtos = evalutionDao.selectDetail(id);
            Double start = evalutionDao.selectStarsDouble(id);
            if (detailDtos!=null&&advertisement!=null){
                HashMap<String, Object> detailMap = new HashMap<>();
                detailMap.put("advmsg",advertisement);
                detailMap.put("usermsg",detailDtos);
                detailMap.put("advstarts",start);
                if (detailMap!=null){
                    return R.ok(detailMap);
                }
            }

        }
        return R.fail("系统繁忙");
    }
}